import java.io.File;
import java.io.FileReader;
import sk.tuke.magsa.tools.generator.ApplicationGenerator;
import sk.tuke.magsa.tools.generator.CollectionTemplateGenerator;
import sk.tuke.magsa.tools.generator.DatabaseScriptGenerator;
import sk.tuke.magsa.tools.metamodel.Entity;
import sk.tuke.magsa.tools.metamodel.Model;
import sk.tuke.magsa.tools.metamodel.ui.Column;
import sk.tuke.magsa.tools.metamodel.ui.Component;
import sk.tuke.magsa.tools.metamodel.ui.Table;
import sk.tuke.magsa.tools.parserext.Parser;
import sk.tuke.magsa.tools.parserxml.UIProcessor;

//import sk.tuke.magsa.tools.metamodel.*;
//import sk.tuke.magsa.tools.parser.*;

public class Make {
    public static void main(String[] args) throws Exception {
        Model model;
        
//        File dir = new File("model/entities");
//        LineParser parser  = new LineParser();
//        model = parser.parseDir(dir);
//        
        
        
        Parser parsetext = new Parser();
        model = parsetext.parse(new FileReader("model/model.el"));
        
//        ConstraintBuilder builder = new PersonalistikaObmedzenia();
//        builder.compose(model);
        
        UIProcessor uiProcessor = new UIProcessor(
                new FileReader("model/ui.xml"), 
                new File("model/ui.xsd")
        );
        uiProcessor.compose(model);
        Table[] ta = model.getUi().getTables();
        Column[] co = ta[0].getColumns();
        Component[] cp = ta[0].getComponents();
        
        co[0].getLabel();
        co[0].getPropertyName();
        co[0].getLength();
        new DatabaseScriptGenerator(model).generate();
        new CollectionTemplateGenerator<Entity>(model, "entity_class", model.getEntities()).generate();
        new CollectionTemplateGenerator<Entity>(model, "dao_interface", model.getEntities()).generate();
        new CollectionTemplateGenerator<Entity>(model, "dao_impl", model.getEntities()).generate();
        new CollectionTemplateGenerator(model, "ui_form", uiProcessor.getUi().getForms()).generate();
        new CollectionTemplateGenerator(model, "ui_table", uiProcessor.getUi().getTables()).generate();
        
        
        new ApplicationGenerator(model).generate();
        
        
        
        //Print the model
        System.out.println(model);
    }
}
